package com.masiyi.sentinel.controller;

import com.alibaba.csp.sentinel.AsyncEntry;
import com.alibaba.csp.sentinel.SphO;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.masiyi.sentinel.service.AsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestAsyncController {

    @Autowired
    AsyncService asyncService;

    @GetMapping("/async")
    public void hello() {

        AsyncEntry asyncEntry = null;
        try {
            asyncEntry = SphU.asyncEntry("testSentinel_async");
            asyncService.hello();
        } catch (BlockException e) {
            System.out.println("系统繁忙");
        }finally {
            if (asyncEntry != null) {
                asyncEntry.exit();
            }
        }
    }


}
